package com.example.concurrency.chapter6;

import java.util.concurrent.locks.LockSupport;

public class LockSupportTests {
    public static void main(String[] args) {
        // testPark_1();
        // testPark_2();
        testPark_3();
    }

    private static void testPark_1(){
        // 线程将被挂起
        LockSupport.park();
    }

    private static void testPark_2(){
        // 获取许可证
        LockSupport.unpark(Thread.currentThread());
        LockSupport.park();
    }

    private static void testPark_3() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                LockSupport.park();
            }
        });

        try {
            Thread.sleep(3000);
        }catch (InterruptedException e){}
        // 中断线程
        thread.interrupt();
    }


}
